<template>
  <div class="app-container">
    <div class="title">
      <div class="step1 active"><span>①</span>基本信息<span></span>———</div>
      <div class="step2"><span>②</span>标书信息</div>
    </div>
    <div class="top">
      <div class="left"><img src="@/assets/images/icon/leftIcon.png" alt="" srcset=""
          style="width: 15px;height: 14px;">基本信息</div>
      <!-- <div class="right"><el-button type="primary" size="mini" @click="handleQuery">下达</el-button> -->
    </div>
    <el-form label-width="120px" label-position="left" :model="form" :rules="rules" ref="form">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="招标项目名称： " prop="projectName">
            <el-input v-model="form.projectName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招标方：" label-width="100px">
            <!-- <el-input v-model="form.tenderer"></el-input> -->
            <el-select v-model="form.tenderer" placeholder="招标方">
              <el-option :label="i.dictName" :value="i.dataDictId" v-for="i in tendererList"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="代理机构：">
            <el-input v-model="form.agency"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招标平台：" label-width="100px">
            <!-- <el-input v-model="form.tenderPlatform"></el-input> -->
            <el-select v-model="form.tenderPlatform" placeholder="招标平台">
              <el-option :label="i.dictName" :value="i.dataDictId" v-for="i in tenderPlatformList"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="所属专业：" prop="major">
            <!-- <el-input v-model="form.major"></el-input> -->
            <el-select v-model="form.major" placeholder="所属专业">
              <el-option :label="i.dictName" :value="i.dataDictId" v-for="i in majorList"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="技术负责人：" label-width="100px">
            <!-- <el-input v-model="form.headOfTech"></el-input> -->
            <el-select v-model="form.headOfTech" placeholder="选择负责人">
              <el-option :label="i.dictName" :value="i.dataDictId" v-for="i in headOfTechList"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="开标时间：">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.tenderDate"
              style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="网址：" label-width="100px">
            <el-input v-model="form.url"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="预计竞争单位：">
            <el-input v-model="form.expectedCompetitor"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中标金额：" label-width="100px">
            <el-input v-model="form.amount"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="是否总承包：">
            <el-radio-group v-model="form.whetherGeneralContract">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否中标 ：" label-width="100px" prop="whetherWinBid">
            <el-radio-group v-model="form.whetherWinBid">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否完成：" label-width="100px">
          <div v-if="isComplete">
            {{ form.whetherComplete ? '是' : '否' }}
          </div>
            <el-radio-group v-else v-model="form.whetherComplete">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="保证金金额是否退还：" label-width="140px">
            <el-radio-group v-model="form.whetherRefund">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="退还金额" label-width="100px">
            <el-input v-model="form.refundAmount" :disabled="form.whetherRefund == false" placeholder="退还金额"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="退还联系方式：" label-width="120px">
            <el-input v-model="form.refundContact"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="上传通知书">
            <!-- <el-input v-model="form.name"></el-input> -->
            <el-upload :show-file-list="true" :action="uploadUrl" :before-upload="handleBeforeUpload"
              :on-success="handleUploadSuccess" :on-error="handleUploadError" :headers="config" :on-change="handleChange"
              :file-list="fileList" :on-remove="handleRemove">
              <el-button size="small" type="primary">点击上传</el-button>
              <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="投标截至时间：" label-width="120px">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.bidDeadline"
              style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="form.giveRemark"></el-input>
      </el-form-item>
      <el-button type="primary" @click="onSubmit('next')" v-hasPermi="['system:task:edit']">下一步</el-button>
      <el-button type="primary" @click="onSubmit('save')" v-hasPermi="['system:task:edit']" >保存</el-button>
    </el-form>
  </div>
</template>
<script>
import {
  getToken
} from '@/utils/auth'
import { zdlistDetails } from "@/api/api.js";
import { update, getDetails, saveMaterial } from "@/api/task/task";
export default {
  name: "Online",
  data() {
    return {
      fileList: [],
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      dialogFormVisible: false,
      headOfTechList: [],
      majorList: [],
      tenderPlatformList: [],
      tendererList: [],
      isComplete: false, // 是否已完成
      form: {
        agency: '',//代理机构
        amount: '',//中标金额
        bidDeadline: '',//截止日期
        uploadNotification: '',//通知书
        bidDeadline: '',
        projectName: '',
        tenderer: '',
        tenderPlatform: '',
        major: '',
        headOfTech: '',
        tenderDate: '',
        url: '',
        expectedCompetitor: '',
        whetherGeneralContract: false,
        whetherWinBid: false,
        whetherComplete: false,
        whetherRefund: false,
        refundAmount: '',
        refundContact: '',
        bidDeadline: '',
        giveRemark: ''
      },
      rules: {
        // projectName: [
        //   { required: true, message: '请输入名称', trigger: 'blur' },
        // ],
        // 'major': [
        //   { required: true, message: '请选择所属专业', trigger: 'blur' },
        // ],
        // whetherWinBid: [
        //   { required: true, message: '请选择是否中标', trigger: 'blur' },
        // ],
      },
      formLabelWidth: '120px',
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        userName: undefined
      },
      config: {

      },
      tenderId: '',
      projectName: ''
    };
  },
  created() {
    this.config['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
    this.tenderId = this.$route.query.tenderId
    this.projectName = this.$route.query.projectName
    // console.log(this.tenderId, 'this.tenderId')
    this.getList();
    this.tenderer()
    this.tenderPlatform()
    this.major()
    this.headOfTech()
  },
  methods: {
    handleRemove(file, fileList) {
      this.fileList = fileList
      // this.fileList = fileList
    },
    handleChange(file, fileList) {
      this.fileList = fileList;
      // console.log(fileList, 'fileList')
    },
    async tenderer() {//招标方
      let res = await zdlistDetails(1)
      this.tendererList = res.data.children
    },
    async tenderPlatform() {
      let res = await zdlistDetails(2)
      this.tenderPlatformList = res.data.children
    },
    async major() {
      let res = await zdlistDetails(3)
      this.majorList = res.data.children

    },
    async headOfTech() {//技术负责人
      let res = await zdlistDetails(4)
      this.headOfTechList = res.data.children
    },
    // 提交表单
    onSubmit(val) {
      let uploadNotification = this.fileList.map(item => {
        return {
          name: item.response ? item.response.originalFilename : item.name,
          url: item.response ? item.response.originalFilename : item.url
        }
      })
      this.form.uploadNotification = JSON.stringify(uploadNotification)
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let res = await update(this.form)
          if (val == 'save') {
            this.$message.success('保存成功');
          } else {
            this.$router.push({
            path: '/myAffairs/assignment/template',
            query: {
              tenderId: this.tenderId,
              projectName: this.projectName
            }
          })
          }
        }
      });
    },
    // 上传前校检格式和大小
    handleBeforeUpload(file) {
      // 校检文件大小
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      return true;
    },
    handleUploadSuccess(res, file) {
      // 获取富文本组件实例
      let quill = this.Quill;
      // 如果上传成功
      if (res.code == 200) {
        // this.fileList.push({
        //   name: res.originalFilename,
        //   url: res.fileName
        // })
        console.log(this.fileList)
      } else {
        this.$message.error("图片插入失败");
      }
    },
    handleUploadError() {
      this.$message.error("图片插入失败");
    },
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      getDetails(this.tenderId).then(response => {
        this.form = response.data
        this.isComplete = this.form.whetherComplete; // 判读是否已完成
        this.fileList = response.data.uploadNotification ? JSON.parse(response.data.uploadNotification) : []
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$router.push({
        path: '/assignment/details',
        query: {
          tenderId: row.tenderId,
          projectName: row.projectName
        }
      })
      // this.$modal.confirm('是否确认强退名称为"' + row.userName + '"的用户？').then(function () {
      //   return forceLogout(row.tokenId);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("强退成功");
      // }).catch(() => { });
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep .el-select {
  width: 100% !important;
}

.title {
  display: flex;
  color: #A9A9AA;

  .active {
    color: #157DFA;
  }

  .step1 {
    margin-right: 10px;
  }

  span {
    margin-right: 8px;
  }
}

.top {
  display: flex;
  justify-content: space-between;
  color: #333;
  margin: 15px 0;

  .left {
    img {
      margin-right: 10px;
    }
  }

  .right {}
}
</style>
